home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / ccKeywordsAndDescription.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  4.8 KB  |  163 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_pageKeywordsAndDescription;
  6.  
  7. var KEYWORD_TAG;
  8. var DESCRIPTION_TAG;
  9.  
  10. //---------------     API FUNCTIONS    ---------------
  11.  
  12. //Only run if there's an open document with a DOM
  13. function canAcceptCommand()
  14. {
  15. var docExists = false;
  16.   
  17.   if (dw.getDocumentDOM() != null)
  18.   {
  19.     if ( dw.getFocus() != 'browser' && dw.getDocumentDOM().getParseMode() == 'html')
  20.      docExists = true;
  21.   }
  22.  
  23.   return docExists;
  24. }
  25.  
  26. //Return list of buttons to draw
  27. function commandButtons(){
  28.  // return new Array(MM.BTN_OK,"okClicked()", MM.BTN_Cancel, "cancelClicked()", MM.BTN_Help, "displayHelp()");
  29.     return new Array( "PutButtonsOnBottom",
  30.                          "OkButton", MM.BTN_OK,     "okClicked()", 
  31.                          "CancelButton", MM.BTN_Cancel,  "cancelClicked()",
  32.                          "PutButtonOnLeft", MM.BTN_Help,    "displayHelp()");
  33.  
  34. }
  35.  
  36. //---------------     LOCAL FUNCTIONS    ---------------
  37.  
  38. function okClicked()
  39. {
  40.   applyChanges();
  41.   window.close();
  42. }
  43.  
  44. function cancelClicked()
  45. {
  46.   window.close();
  47. }
  48.  
  49.  
  50. function initializeUI()
  51. {
  52.   //initialize metatag pointers
  53.   KEYWORD_TAG = findMetaTag("keywords");
  54.   DESCRIPTION_TAG = findMetaTag("description");
  55.  
  56.   if (KEYWORD_TAG)
  57.   { //if existing keyword meta tag found, load it's content into this UI
  58.     document.theForm.keywords.value = unencodeQuotes(KEYWORD_TAG.getAttribute("content"));
  59.   }
  60.  
  61.   if (DESCRIPTION_TAG)
  62.   { //if existing description meta tag found, load it's content into this UI
  63.     document.theForm.description.value = unencodeQuotes(DESCRIPTION_TAG.getAttribute("content"));
  64.   }
  65.  
  66. }
  67.  
  68. function applyChanges()
  69. {
  70.   var insertString = "";  //the string of new tags to insert, if any
  71.  
  72.   //get keywords from the UI
  73.   var keywords = document.theForm.keywords.value;
  74.   if (KEYWORD_TAG)
  75.   { //if existing meta tag, rewrite it's content attribute
  76.     KEYWORD_TAG.setAttribute("content", keywords);
  77.   }
  78.   else if (keywords)
  79.   { //if no keyword meta tag exists, generate a string for the new tag
  80.     insertString += '<meta name="keywords" content="' + encodeQuotes(keywords) + '">';
  81.   }
  82.  
  83.   //get description from the UI
  84.   var description = document.theForm.description.value;
  85.   if (DESCRIPTION_TAG)
  86.   { //if existing meta tag, rewrite it's content attribute
  87.     DESCRIPTION_TAG.setAttribute("content", description);
  88.   }
  89.   else if (description)
  90.   { //if no description meta tag exists, append a string for the new tag
  91.     insertString += '<meta name="description" content="' + encodeQuotes(description) + '">';
  92.   }
  93.  
  94.   //if new tag(s) to be inserted, insert them. DW knows that meta tags belong in the HEAD tag
  95.   if (insertString)
  96.   {
  97.     var theDom = dw.getDocumentDOM();
  98.  
  99.     //special case for wierd bug 77420. For template instances, basic insertHTML() fails.
  100.     //For those cases, just append the new meta tags to the title tag.
  101.     if (theDom.documentElement.outerHTML.indexOf('BeginEditable name="doctitle"') > 0 //if any type of template instance
  102.         || theDom.documentElement.outerHTML.indexOf('BeginEditable "doctitle"') > 0)
  103.     { //force the tags after the TITLE tag.
  104.       var titleTags = theDom.getElementsByTagName("TITLE");
  105.       if (titleTags && titleTags.length>0)
  106.       {
  107.         titleTags[0].outerHTML += insertString;  //add string to title tag
  108.       }
  109.     }
  110.     else
  111.     { //normal case: insertHTML and let DW figure out where to put it 
  112.       // #78528 - but don't replace current selection (added 0 second argument) 
  113.       theDom.insertHTML(insertString,0);
  114.     }
  115.   }
  116. }
  117.  
  118.  
  119. //Given a meta tag name (such as "keyword") returns a pointer to the
  120. //first tag with that name, or null if none found.
  121. function findMetaTag(tagName)
  122. {
  123.   var tagPointer = null;  //return value for function
  124.   var theDom = dw.getDocumentDOM();
  125.   var metaTagName;
  126.  
  127.   if (tagName)  //if tagName passed in
  128.   {
  129.     tagName = tagName.toLowerCase();  //force lowercase
  130.  
  131.     //find any existing meta tags
  132.     var allMetaTags = theDom.getElementsByTagName("META");
  133.     if (allMetaTags && allMetaTags.length > 0) //if meta tags exist
  134.     {
  135.       for (i=0; i<allMetaTags.length && !tagPointer; i++)  //scan meta tags
  136.       {
  137.         metaTagName = allMetaTags[i].getAttribute("name");
  138.         if (metaTagName)
  139.         {
  140.           metaTagName = metaTagName.toLowerCase(); //force lowercase
  141.           if (metaTagName == tagName) //if meta tag found, point to it (only 1st one)
  142.           {
  143.             tagPointer = allMetaTags[i];
  144.           }
  145.         }
  146.       }
  147.     }
  148.   }
  149.   return tagPointer;
  150. }
  151.  
  152.  
  153. function encodeQuotes(theStr)
  154. {
  155.   return theStr.replace(/"/g,""");
  156. }
  157.  
  158.  
  159. function unencodeQuotes(theStr)
  160. {
  161.   return theStr.replace(/\"/g,'"');
  162. }
  163.